package com.iknow.activity;

import android.app.Activity;
import android.content.Intent;
import android.os.AsyncTask.Status;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.Button;
import android.widget.ProgressBar;
import com.iknow.data.SubscribeTag;
import com.iknow.task.GenericTask;
import com.iknow.task.TaskAdapter;
import com.iknow.task.TaskParams;
import com.iknow.task.TaskResult;
import com.iknow.ui.model.SubscribeTagAdapter;
import com.iknow.util.Loger;
import com.iknow.view.widget.MyListView;
import com.mobclick.android.MobclickAgent;
import java.util.ArrayList;
import java.util.List;

public class FlagItemChildActivity extends Activity
{
  private final String TAG = "FlagItemChildActivity";
  private List<SubscribeTag> list = null;
  private AdapterView.OnItemClickListener listItemClickListener;
  private Button mBackButton;
  protected MyListView mListView;
  private TaskAdapter mListener;
  protected SubscribeTagAdapter mTagAdapter;
  private FlagItemChildTask mTask = null;
  protected ProgressBar pb;
  protected Button refresh;

  public FlagItemChildActivity()
  {
    this.listItemClickListener = new AdapterView.OnItemClickListener(this)
    {
      public void onItemClick(, View paramView, int paramInt, long paramLong)
      {
        SubscribeTag localSubscribeTag = this.this$0.mTagAdapter.getItem(paramInt);
        Intent localIntent = new Intent();
        localIntent.setClass(this.this$0, TagQingboActivity.class);
        localIntent.putExtra("tag", localSubscribeTag);
        MobclickAgent.onEvent(this.this$0, "tag_click", localSubscribeTag.getTagName());
        this.this$0.startActivity(localIntent);
      }
    };
    this.mListener = new TaskAdapter(this)
    {
      public String getName()
      {
        return "FlagItemChildTask";
      }

      public void onPostExecute(, TaskResult paramTaskResult)
      {
        if (paramTaskResult == TaskResult.OK)
          this.this$0.mTagAdapter.setTagList(FlagItemChildActivity.access$0(this.this$0));
        this.this$0.mTagAdapter.notifyDataSetChanged();
        this.this$0.pb.setVisibility(8);
      }

      public void onPreExecute()
      {
        this.this$0.pb.setVisibility(0);
        this.this$0.refresh.setVisibility(8);
      }
    };
  }

  protected void getSubscribeTag()
  {
    if ((this.mTask != null) && (this.mTask.getStatus() == AsyncTask.Status.RUNNING));
    while (true)
    {
      return;
      this.mTask = new FlagItemChildTask(this, null);
      this.mTask.setListener(this.mListener);
      this.mTask.execute(new TaskParams[0]);
    }
  }

  protected void initView()
  {
    setContentView(2130903128);
    this.mBackButton = ((Button)findViewById(2131296342));
    this.mTagAdapter = new SubscribeTagAdapter(getLayoutInflater());
    this.mListView = ((MyListView)findViewById(2131296535));
    this.pb = ((ProgressBar)findViewById(2131296345));
    this.refresh = ((Button)findViewById(2131296344));
    this.refresh.setText("刷新");
    this.refresh.setVisibility(8);
    this.mListView.setAdapter(this.mTagAdapter);
    this.mListView.setOnItemClickListener(this.listItemClickListener);
    this.mBackButton.setOnClickListener(new View.OnClickListener(this)
    {
      public void onClick()
      {
        this.this$0.finish();
      }
    });
    this.refresh.setOnClickListener(new View.OnClickListener(this)
    {
      public void onClick()
      {
        this.this$0.pb.setVisibility(8);
        this.this$0.getSubscribeTag();
      }
    });
  }

  protected void onCreate(Bundle paramBundle)
  {
    super.onCreate(paramBundle);
    requestWindowFeature(1);
    initView();
    getSubscribeTag();
  }

  private class FlagItemChildTask extends GenericTask
  {
    private String mErrorMessage;

    protected TaskResult _doInBackground()
    {
      TaskResult localTaskResult;
      String[] arrayOfString;
      try
      {
        arrayOfString = this.this$0.getIntent().getStringArrayExtra("child");
        FlagItemChildActivity.access$1(this.this$0, new ArrayList());
        int i = 0;
        if (i >= arrayOfString.length)
        {
          String str = this.this$0.getIntent().getStringExtra("tag");
          this.this$0.mTagAdapter.resetAllTagName(str);
          localTaskResult = TaskResult.OK;
          return localTaskResult;
        }
        SubscribeTag localSubscribeTag = new SubscribeTag();
        localSubscribeTag.setTagName(arrayOfString[i]);
        FlagItemChildActivity.access$0(this.this$0).add(localSubscribeTag);
        ++i;
      }
      catch (Exception localException)
      {
        while (true)
        {
          this.mErrorMessage = "网络超时,稍后再试";
          Loger.e("FlagItemChildActivity", this.mErrorMessage);
          localTaskResult = TaskResult.FAILED;
        }
      }
    }
  }
}